home *** CD-ROM | disk | FTP | other *** search
- /* uuencode.c - convert files to ascii-encoded form
- * Usage: uuencode [filename] < infile
- *
- * If [filename] isn't specified, "/dev/stdout" is the default. This allows
- * use of my uudecode as a pipeline filter.
- *
- * Written and placed in the public domain by Phil Karn, KA9Q
- * 31 March 1987
- */
- #include <stdio.h>
- #define LINELEN 45
-
- main(argc,argv)
-
- int argc;
- char *argv[];
-
- {
- char linebuf[LINELEN];
- register char *cp;
- register int linelen;
- FILE *in, *out;
-
- if (argc < 3)
- {
- printf("\n Usage: uuencode infile outfile\n");
- return(0);
- }
-
- in = fopen(argv[1],"rb");
- out = fopen(argv[2],"w");
-
- fprintf(out,"begin 0666 %s\n",argv[1]);
-
- for(;;)
- {
- linelen = fread(linebuf,1,LINELEN,in);
-
- if (linelen <= 0)
- break;
-
- fputc(' ' + linelen,out); // Record length
-
- for(cp = linebuf; cp < &linebuf[linelen]; cp += 3)
- {
- fputc(' ' + ((cp[0] >> 2) & 0x3f),out);
- fputc(' ' + (((cp[0] << 4) & 0x30) | ((cp[1] >> 4) & 0xf)),out);
- fputc(' ' + (((cp[1] << 2) & 0x3c) | ((cp[2] >> 6) & 0x3)),out);
- fputc(' ' + (cp[2] & 0x3f),out);
- }
- fputc('\n',out);
- }
- fprintf(out," \n"); /* 0-length null record */
- fprintf(out,"end\n");
-
- fclose(out);
- fclose(in);
-
- }
-